Skip to content

refactor(dev): EpochStore staging/leases/recovery on Effect Semaphore + Exit-aware saga (wave 3.5 stage 3, PR 4) - #161

Merged
ScriptedAlchemy merged 1 commit into
mainfrom
wave35-s3/epoch-store
Sep 1, 2026
Merged

refactor(dev): EpochStore staging/leases/recovery on Effect Semaphore + Exit-aware saga (wave 3.5 stage 3, PR 4)#161
ScriptedAlchemy merged 1 commit into
mainfrom
wave35-s3/epoch-store

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

Final subsystem of #152 stage 3, sequenced last per the blast-radius audit: EpochStore carries the repo's cross-process durability contracts (injected durabilityStorage/move/cleanupRemove seams pin exact fs-operation order), so it went after the three smaller seams.

  • Mutexes are structural. The per-store transition queue and the process-wide per-.agent-bundle lease queue become Semaphore(1) permits (withPermit, FIFO like the serial queues they replace). Cross-instance lease sharing is unchanged: one mutex + one reference-count map per project path, so leases survive across store instances.
  • Publication is an Exit-aware compensation saga. The commit sequence (exists-check → staged-tree fsync pass → marker removal → rename → parent fsync → publisher pre-activation → metadata writes) is one Effect; its rollback branch mirrors progress exactly as before — post-rename failures classify as EpochPostCommitDurabilityError/EpochPostCommitCleanupError, pre-rename failures roll back the moved paths and the publisher-owned receipt concurrently with per-compensation Exit capture, aggregating into the identical AggregateError shape.
  • Staging-root removal is deliberately not a scope finalizer (documented in-code): the pre-Effect finally let a removal failure replace the outcome, and Effect finalizers must be infallible (stage-2 lesson) — so the publish path captures the attempt's Exit, removes the root, then unwraps.
  • Retention (#cleanupUnderLease) runs eligible deletions concurrently via Effect.forEach + per-element Exit, keeping the labeled, sorted EpochCleanupError aggregation and the sidecar-before-directory-before-metadata retry ordering.
  • Leaf fs validation helpers (#verifyStaging, #validateActiveEpoch, #syncTree, atomic JSON writes) stay imperative and identity-lifted — their operation order is the durability contract the seam tests pin.

Parity (all suites unchanged, zero pin flips)

  • epoch-store.test.ts (43 cases incl. fsync commit order, cross-store leases, concurrent final-release, post-commit classification, publisher-rollback races): green
  • Full unit pool: 1999 passed / 5 documented skips / 0 failed
  • Integration (epoch-heavy consumers): mcp-session-service + target-mcp-runtime: 35 passed / 0 failed
  • pnpm lint + pnpm typecheck: green
  • Changeset: patch (internal rewrite).

Refs #152.

@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f6038ea

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agent-bundle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T17:54:45.067903Z f6038ea PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ScriptedAlchemy
ScriptedAlchemy merged commit f596377 into main Sep 1, 2026
4 of 9 checks passed
ScriptedAlchemy added a commit that referenced this pull request Sep 1, 2026
Rebased survivors of the stranded deslop/wave-3.5 commit (5a8723423)
onto current main. Applied:

- finalizers: sqlite connection close and Flight reader cancel no longer
  mask the original failure when teardown itself throws
- state drivers: shared pending-open tracker replaces the verbatim
  trackPendingOpen/close-drain duplication; drop runPromise(Effect.fail)
  ceremony in favor of direct rejections
- boundaries: remove the unused runSyncExit export from both seams, the
  dead ScopedEffectRuntime E type parameter from the rsc-runtime copy
  (matching the dev-seam copy), and the redundant string ternary in
  toDevError/toRuntimeError
- delete dead epoch-lease-registry.ts (zero importers; #161 rewrote the
  same concept in epoch-store.ts); dedupe boundRenderEventStream through
  emitBoundRenderEvent; trim migration-narration comments

Dropped as superseded: the reconciler progress-queue rework (#172
rebuilt that path with a demand-bounded design), the dev-seam trim of
interruptWhenAborted/runPromiseExit (#164 fixed and kept them with
tests), the sqlite #commit self-rewrite (#171 rewrote #commit), and the
lint-plugin inlining (#164 expanded the plugin around those helpers).
@ScriptedAlchemy
ScriptedAlchemy deleted the wave35-s3/epoch-store branch September 3, 2026 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant